package myalg.graphs.alg.dijkstra;

import myalg.graphs.Caption;
import myalg.graphs.Edge;
import myalg.graphs.Graph;
import myalg.graphs.Vertex;
import myalg.graphs.alg.BasicAlgorithm;
import myalg.graphs.ui.GraphPanel;

import javax.swing.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Pavel Belevich
 *         Date: Jun 13, 2012
 *         Time: 2:22:36 PM
 */
public class Main {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);

        Graph graph = new Graph();

        final Map<Edge, Double> w = new HashMap<Edge, Double>();
        final Map<Vertex, Double> d = new HashMap<Vertex, Double>();

        graph.setCaption(new Caption() {
            @Override
            public String getCaption(Vertex v) {
                return String.valueOf(d.get(v));
            }

            @Override
            public String getCaption(Edge e) {
                return String.valueOf(w.get(e));
            }
        });

        Vertex v1 = new Vertex(-75.0, -100.0, "1");  graph.getVertices().add(v1);
        Vertex v2 = new Vertex(0.0, -110.0, "2");    graph.getVertices().add(v2);
        Vertex v3 = new Vertex(0.0, 0.0, "3");       graph.getVertices().add(v3);
        Vertex v4 = new Vertex(130.0, 5.0, "4");     graph.getVertices().add(v4);
        Vertex v5 = new Vertex(50.0, 50.0, "5");     graph.getVertices().add(v5);
        Vertex v6 = new Vertex(-60.0, 40.0, "6");    graph.getVertices().add(v6);

        Edge e1 = new Edge(v1,v2);  graph.getEgdes().add(e1);   w.put(e1, 7.0);
        Edge e2 = new Edge(v1,v3);  graph.getEgdes().add(e2);   w.put(e2, 9.0);
        Edge e3 = new Edge(v2,v3);  graph.getEgdes().add(e3);   w.put(e3, 10.0);
        Edge e4 = new Edge(v1,v6);  graph.getEgdes().add(e4);   w.put(e4, 14.0);
        Edge e5 = new Edge(v6,v3);  graph.getEgdes().add(e5);   w.put(e5, 2.0);
        Edge e6 = new Edge(v2,v4);  graph.getEgdes().add(e6);   w.put(e6, 15.0);
        Edge e7 = new Edge(v3,v4);  graph.getEgdes().add(e7);   w.put(e7, 11.0);
        Edge e8 = new Edge(v4,v5);  graph.getEgdes().add(e8);   w.put(e8, 6.0);
        Edge e9 = new Edge(v5,v6);  graph.getEgdes().add(e9);   w.put(e9, 9.0);


        GraphPanel graphPanel = new GraphPanel(graph);
        frame.getContentPane().add(graphPanel);

        frame.setVisible(true);

//        BasicAlgorithm dijkstra = new Dijkstra(graph, v1, d);
//        dijkstra.addAlgorithmListener(graphPanel);
//        dijkstra.run();
    }

}
